import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tencent_trtc_cloud/trtc_cloud_video_view.dart';
import 'package:wk_robot2/app/nets/NetWorkManager.dart';
import 'package:wk_robot2/app/widget/CommonWidgets.dart';

import '../../../event/WkEventListener.dart';
import '../../../style/app_colors.dart';
import '../../../widget/CustomJoystick.dart';
import '../controllers/video_live_controller.dart';
import 'LoadingView.dart';
import 'MoveWidget.dart';
import 'RotatingCircle.dart';

class VideoLiveView extends GetView<VideoLiveController> {
  var _actionImg = [
    'assets/images/mini_sayhello.webp',
    'assets/images/mini_naughty.webp',
    'assets/images/mini_hug.webp',
    'assets/images/mini_shake_hand.webp',
    'assets/images/mini_bow.webp',
    'assets/images/mini_sell_moe.webp',
  ];
  var _actionName = [
    '打招呼',
    '调皮',
    '拥抱',
    '握手',
    '鞠躬',
    '飞吻',
  ];
  var _actionResName = [
    "Surveillance_0001",
    "Surveillance_0002",
    "Surveillance_0003",
    "Surveillance_0004",
    "Surveillance_0005",
    "Surveillance_0006"
  ];
  TRTCCloudVideoView? trtcCloudVideoView;
  int _backgroundColor = 0xFFEEF1F7;
  int _textcolor = 0xff3f5579;
  final FocusNode _focusNode = FocusNode();

  @override
  Widget build(BuildContext context) {
    if (trtcCloudVideoView == null) {
      trtcCloudVideoView = TRTCCloudVideoView(
        key: UniqueKey(), // 确保每次重建时都有新的key
        onViewCreated: (int viewId) {
          controller.startRemoteView(viewId);
        },
      );
    }


    return Scaffold(
        appBar: null,
        backgroundColor: Color(_backgroundColor),
        body:OrientationBuilder(
        builder: (context, orientation) {
          controller.isPortrait.value = (orientation == Orientation.portrait);
          ScreenUtil.init(context, designSize:controller.isPortrait.value ? Size(750, 1624) : Size(1624, 750), splitScreenMode: false,
            minTextAdapt: true,);
          controller.hideSystemUIMode(orientation == Orientation.portrait);
          return controller.isPortrait.value
              ? Padding(
              padding:
              EdgeInsets.only(top: MediaQuery.of(context).padding.top),
              child: Stack(
                children: [
                  ///标题栏
                  Positioned(
                    left: 34.w,
                    top: 20.h,
                    child: GestureDetector(
                      onTap: () {
                        Get.back();
                      },
                      child: Image.asset(
                        'assets/images/ic_back2.png',
                        //height: 40.h,
                        width: 40.h,
                        fit: BoxFit.fill, // 设置图片填充方式
                      ),
                    ),
                  ),
                  Positioned(
                    left: 303.w,
                    top: 19.h,
                    child: Text('视频通话',
                        style: TextStyle(
                          color: Color(0xFF091936),
                          fontSize: 36.sp,
                          fontWeight: FontWeight.bold, // 设置加粗
                        )),
                  ),

                  /// 视频通话画面
                  Positioned(
                    top: 88.h,
                    child: SizedBox(
                      width: ScreenUtil().screenWidth,
                      height: 422.h,
                      child: trtcCloudVideoView,
                    ),
                  ),
                  Positioned(
                      right: 20.w,
                      top: 418.h,
                      child: GestureDetector(
                        onTap: () {
                          controller.changeScrennDirection(false);
                        },
                        child: Image.asset(
                          'assets/images/ic_screen_mode_switch.png',
                          width: 72.w,
                          fit: BoxFit.fill, // 设置图片填充方式
                        ),
                      )),
                  Positioned(
                    top: 279.h,
                      left: 355.w,
                      width: 40.h,
                      height: 40.h,
                      child: Obx(() => controller.isVideoLoading.value? LoadingView(): Container(height: 0,width: 0,))),
                  // 黑色遮罩
                  Positioned(
                      top: 88.h,
                      left: 0,
                      right: 0,
                      height: 422.h,
                      child: Obx(() => (controller.isConnectionLostOver10s.value || controller.isPowerBelow20.value) ? Container(
                        color: Colors.black,
                      ):
                      Container(width: 0,)
                      )
                  ),
                  // 中间位置错误提示文本
                  Positioned(
                    top: 236.h,
                    left: 0,
                    right: 0,
                    child:Center(
                      child: Obx(() => Text(
                        controller.isConnectionLostOver10s.value ? controller.connectionLostErrorText :
                        (controller.isPowerBelow20.value ? controller.powerBelow20ErrorText : ""),
                        style: TextStyle(
                          color: Colors.white, // #ffffffff 对应白色
                          fontSize: 30.sp, // 30sp 转换为 Flutter 中的 fontSize
                        ),
                        textAlign: TextAlign.center, // 如果需要居中对齐文本
                      ),)
                    )

                  ),
                  //顶部错误提示文本
                  Positioned(
                    top: 88.h,
                      left: 0,
                      right: 0,
                      height: 72.h,
                      child: Obx(() =>
                      (controller.isConnectionLost.value || controller.isPowerBelow30.value) ? Container(
                        color: Color(0xFFF1DBD6),
                        child: Row(
                          children: [
                            SizedBox(width: 40.w,),
                            Image.asset('assets/images/ic_warn_red.png',width: 30.w,height: 30.h,
                            ),
                            SizedBox(width: 20.w,),
                            Text(controller.isConnectionLost.value ? controller.connectionLostErrorText:controller.powerBelow30ErrorText,
                                style: TextStyle(fontSize: 26.sp,color: Color(0xFFFF0C0C))),
                          ],
                        ),
                      ) : Container(height: 0,)
                      )

                  ),

                  /// 动作，移动控制和文字播放区域
                  ///
                  /// 移动控制和文字播放区域背景
                  Positioned(
                      top: 720.h,
                      height: 726.h,
                      width: ScreenUtil().screenWidth,
                      child: Container(
                        color: Color(0xFFF3F6F9),
                      )),

                  /// 标题
                  Positioned(
                    top: 720.h,
                    height: 93.h,
                    width: ScreenUtil().screenWidth,
                    child: Obx(() =>
                        Row(
                          mainAxisAlignment: MainAxisAlignment.center, // 水平居中
                          children: [
                            GestureDetector(
                              onTap: () {
                                controller.isMoveControlViewShowed.value = true;
                              },
                              child: Stack(
                                children: [
                                  controller.isMoveControlViewShowed.value
                                      ? Positioned(
                                    bottom: 0,
                                    child: Container(
                                      width: 138.w, // 设置宽度
                                      height: 12.h, // 设置高度
                                      decoration: BoxDecoration(
                                        color: Color(0xff50e8ff), // 设置背景颜色
                                        borderRadius: BorderRadius.all(
                                            Radius.circular(6)), // 设置圆角半径
                                      ),
                                    ),
                                  )
                                      : Container(
                                    width: 0,
                                    height: 0,
                                  ),
                                  Text(
                                    '移动控制',
                                    style: TextStyle(
                                      color: Color(0xff091936), // 设置文本颜色
                                      fontSize: 32.sp, // 设置字体大小
                                      fontWeight: FontWeight.bold, // 设置加粗
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            Container(
                              width: 50.w,
                              height: 1,
                            ),
                            GestureDetector(
                              onTap: () {
                                controller.isMoveControlViewShowed.value = false;
                              },
                              child: Stack(
                                children: [
                                  controller.isMoveControlViewShowed.value
                                      ? Container(
                                    width: 0,
                                    height: 0,
                                  )
                                      : Positioned(
                                      bottom: 0,
                                      child: Container(
                                        width: 138.w, // 设置宽度
                                        height: 12.h, // 设置高度
                                        decoration: BoxDecoration(
                                          color: Color(0xff50e8ff), // 设置背景颜色
                                          borderRadius: BorderRadius.all(
                                              Radius.circular(6)), // 设置圆角半径
                                        ),
                                      )),
                                  Text(
                                    '文字播报',
                                    style: TextStyle(
                                      color: Color(0xff091936), // 设置文本颜色
                                      fontSize: 32.sp, // 设置字体大小
                                      fontWeight: FontWeight.bold, // 设置加粗
                                    ),
                                  ),
                                ],
                              ),
                            )
                          ],
                        )
                    ),
                  ),


                  Obx(() => controller.isMoveControlViewShowed.value
                  /// 遥控杆
                      ? Positioned(
                      top: 813.h,
                      left: 0,
                      height: 633.h,
                      width: ScreenUtil().screenWidth,
                      child: Stack(
                        children: [
                          Positioned(
                              top: 65.h,
                              left: 136.w,
                              child: Text(
                                '控制移动',
                                style: TextStyle(
                                  color: Color(0xff8296b6), // 设置文本颜色
                                  fontSize: 26.sp, // 设置字体大小
                                ),
                              )),
                          Positioned(
                              top: 65.h,
                              right: 136.w,
                              child: Text(
                                '控制转头',
                                style: TextStyle(
                                  color: Color(0xff8296b6), // 设置文本颜色
                                  fontSize: 26.sp, // 设置字体大小
                                ),
                              )),

                          // 移动控制杆
                          Positioned(
                              top: 105.h,
                              left: 16.w,
                              width: 348.r,
                              height: 348.r,
                              child: MoveWidget(
                                background: 'assets/images/bg_move_portrait.png',
                                backgroundUnenabled: "",
                                icon: 'assets/images/ic_move.png',
                                iconUnenabled: "",
                                radiusBackground: 174.r,
                                radiusIcon: 61.5.r,
                                onChange: (double angle) {
                                  controller.onMoveAngleChange(angle);
                                },
                                onStartMove: () {
                                  controller.isMoving.value = true;
                                },
                                onStopMove: () {
                                  controller.isMoving.value = false;
                                  controller.onMoveStop();
                                },
                                isMoveStick: true,
                                enable: !controller.isVideoLoading.value,
                              )),

                          //头部转动控制杆
                          Positioned(
                              top: 105.h,
                              right: 16.w,
                              width: 348.r,
                              height: 348.r,
                              child: MoveWidget(
                                background: 'assets/images/bg_rotate_portrait.png',
                                backgroundUnenabled: "",
                                icon: 'assets/images/ic_rotate.png',
                                iconUnenabled: "",
                                radiusBackground: 174.r,
                                radiusIcon: 61.5.r,
                                onChange: (double angle) {
                                  controller.onHeadMoveChange(angle);
                                },
                                onStartMove: () {
                                  controller.isMoving.value = true;
                                },
                                onStopMove: () {
                                  controller.isMoving.value = false;
                                  controller.onHeadMoveStop();
                                },
                                enable: !controller.isVideoLoading.value,
                              )),

                          // 提示文字
                          Positioned(
                            left: 38.w,
                            right: 38.w,
                            bottom: 74.h,
                            child: Text(
                              '远程控制机器人动作或移动时，请先通过摄像头确认对面环境，以防机器人磕碰或跌落',
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                color: Color(0xffb7c4da), // 设置文本颜色
                                fontSize: 22.sp, // 设置字体大小
                              ),
                            ),
                          )
                        ],
                      ))

                  /// tts列表
                      : Positioned(
                    top: 813.h,
                    left: 0,
                    height: 553.h,
                    width: ScreenUtil().screenWidth,
                    child: ListView.builder(
                      reverse: true,
                      itemCount: controller.ttsList.length,
                      itemBuilder: (context, index) {
                        return Padding(
                          padding: EdgeInsets.only(bottom: 30.h),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.end,
                            children: [
                              GestureDetector(
                                onTap: (){
                                  controller.editTTS(controller.ttsList[index]);
                                },
                                child: ConstrainedBox(
                                  constraints: BoxConstraints(
                                    maxWidth: 580.w, // 设置最大宽度
                                    //maxHeight: 172.h, // 设置最大高度
                                  ),
                                  child: Container(
                                    decoration: BoxDecoration(
                                      color: Color(
                                          _backgroundColor), // 设置背景颜色
                                      borderRadius: BorderRadius.only(
                                        topLeft: Radius.circular(
                                            30.w), // 左上角圆角半径
                                        bottomLeft: Radius.circular(
                                            30.w), // 左下角圆角半径
                                        bottomRight: Radius.circular(
                                            30.w), // 右下角圆角半径
                                        topRight:
                                        Radius.circular(0), // 右上角无圆角
                                      ),
                                    ),
                                    padding: EdgeInsets.all(30.w),
                                    child: Text(
                                      maxLines: 3, // 设置最大行数为3
                                      overflow: TextOverflow
                                          .ellipsis, // 超过最大行数时显示省略号
                                      controller.ttsList[index].text,
                                      style: TextStyle(
                                        color: Color(0xFF091936),
                                        fontSize: 28.sp,
                                      ),
                                    ),
                                  ),
                                ),
                              )
                              ,
                              Padding(
                                padding: EdgeInsets.only(
                                    right: 16.w, left: 16.w),
                                child: controller
                                    .ttsList[index].isPlaying
                                    ? GestureDetector(
                                  onTap: () {
                                    controller.stopTTS(controller
                                        .ttsList[index]);
                                  },
                                  child: Image.asset(
                                    'assets/images/ic_stop_tts.png',
                                    width: 44.w,
                                    fit: BoxFit.fill, // 设置图片填充方式
                                  ),
                                )
                                    : GestureDetector(
                                  onTap: () {
                                    controller.playTTS(controller
                                        .ttsList[index]);
                                  },
                                  child: Image.asset(
                                    'assets/images/ic_play_tts.png',
                                    width: 44.w,
                                    fit: BoxFit.fill, // 设置图片填充方式
                                  ),
                                ),
                              ),
                              Padding(
                                padding: EdgeInsets.only(right: 20.w),
                                child: GestureDetector(
                                  onTap: () {
                                    controller.deleteTts(
                                        controller.ttsList[index]);
                                  },
                                  child: Image.asset(
                                    'assets/images/ic_delete_tts.png',
                                    width: 44.w,
                                    fit: BoxFit.fill, // 设置图片填充方式
                                  ),
                                ),
                              ),
                            ],
                          ),
                        );
                      },
                    ),
                  )),
                  Positioned(
                    bottom: 427.h,
                    left: 235.w,
                    child: Obx(() =>Text(
                      (controller.ttsList.isEmpty &&
                          !controller.isMoveControlViewShowed.value)
                          ? "添加你希望悟空说的话"
                          : "", // 对应 android:text
                      style: TextStyle(
                        color: Color(
                            0xff3f5579), // 对应 android:textColor="#ff3f5579"
                        fontSize: 28.sp, // 对应 android:textSize="28sp"
                      ),
                    )),
                  ),

                  /// 动作列表
                  Positioned(
                      top: 510.h,
                      left: 0,
                      child: Obx(() =>Container(
                        width: ScreenUtil().screenWidth,
                        height: controller.isActionViewExpanded.value
                            ? 450.h
                            : 210.h,
                        //padding: EdgeInsets.only(top: 21.h),
                        color: Color(0xFFFFFFFF),
                        child: Column(
                          children: [
                            ///第一行动作
                            Container(
                              width: ScreenUtil().screenWidth,
                              padding: EdgeInsets.only(top: 21.h),
                              height: 174.h,
                              child: Row(
                                children: [
                                  Container(
                                    width: ScreenUtil().screenWidth / 4,
                                    alignment: Alignment.center,
                                    child: Column(children: [
                                      controller.isMoving.value || controller.isVideoLoading.value ?
                                      Image.asset(
                                        'assets/images/mini_sayhello.webp',
                                        //width: 95.w,
                                        color: Colors.white.withOpacity(0.3), // 设置透明度为30%
                                        colorBlendMode: BlendMode.modulate,
                                        height: 113.h,
                                        fit: BoxFit.fill, // 设置图片填充方式
                                      ) :
                                      GestureDetector(
                                        onTap: () {
                                          controller.sendActionCmd(
                                              _actionResName[0]);
                                        },
                                        child: Image.asset(
                                          'assets/images/mini_sayhello.webp',
                                          //width: 95.w,
                                          height: 113.h,
                                          fit: BoxFit.fill, // 设置图片填充方式
                                        ),
                                      ),
                                      Text(
                                        '打招呼',
                                        style: TextStyle(
                                          color: (controller.isMoving.value || controller.isVideoLoading.value)? Color(_textcolor).withOpacity(0.3):Color(_textcolor),
                                          fontSize: 22.sp,
                                        ),
                                      )
                                    ]),
                                  ),
                                  Container(
                                    width: ScreenUtil().screenWidth / 4,
                                    alignment: Alignment.center,
                                    child: Column(children: [
                                      controller.isMoving.value || controller.isVideoLoading.value ?
                                      Image.asset(
                                        'assets/images/mini_naughty.webp',
                                        //width: 95.w,
                                        color: Colors.white.withOpacity(0.3), // 设置透明度为30%
                                        colorBlendMode: BlendMode.modulate,
                                        height: 113.h,
                                        fit: BoxFit.fill, // 设置图片填充方式
                                      ) :
                                      GestureDetector(
                                          onTap: () {
                                            controller.sendActionCmd(
                                                _actionResName[1]);
                                          },
                                          child: Image.asset(
                                            'assets/images/mini_naughty.webp',
                                            //width: 86.w,
                                            height: 113.h,
                                            fit: BoxFit.fill, // 设置图片填充方式
                                          )),

                                      Text(
                                        '调皮',
                                        style: TextStyle(
                                          color:(controller.isMoving.value || controller.isVideoLoading.value)? Color(_textcolor).withOpacity(0.3):Color(_textcolor),
                                          fontSize: 22.sp,
                                        ),
                                      )
                                    ]),
                                  ),
                                  Container(
                                    width: ScreenUtil().screenWidth / 4,
                                    alignment: Alignment.center,
                                    child: Column(children: [
                                      controller.isMoving.value || controller.isVideoLoading.value ?
                                      Image.asset(
                                        'assets/images/mini_hug.webp',
                                        //width: 95.w,
                                        color: Colors.white.withOpacity(0.3), // 设置透明度为30%
                                        colorBlendMode: BlendMode.modulate,
                                        height: 113.h,
                                        fit: BoxFit.fill, // 设置图片填充方式
                                      ) :
                                      GestureDetector(
                                          onTap: () {
                                            controller.sendActionCmd(
                                                _actionResName[2]);
                                          },
                                          child: Image.asset(
                                            'assets/images/mini_hug.webp',
                                            //width: 88.w,
                                            height: 113.h,
                                            fit: BoxFit.fill, // 设置图片填充方式
                                          )),
                                      Text(
                                        '拥抱',
                                        style: TextStyle(
                                          color: (controller.isMoving.value || controller.isVideoLoading.value)? Color(_textcolor).withOpacity(0.3):Color(_textcolor),
                                          fontSize: 22.sp,
                                        ),
                                      )
                                    ]),
                                  ),
                                  Container(
                                      width: ScreenUtil().screenWidth / 4,
                                      alignment: Alignment.center,
                                      child: Column(children: [
                                        controller.isMoving.value || controller.isVideoLoading.value ?
                                        Image.asset(
                                          'assets/images/mini_shake_hand.webp',
                                          //width: 95.w,
                                          color: Colors.white.withOpacity(0.3), // 设置透明度为30%
                                          colorBlendMode: BlendMode.modulate,
                                          height: 113.h,
                                          fit: BoxFit.fill, // 设置图片填充方式
                                        ) :
                                        GestureDetector(
                                            onTap: () {
                                              controller.sendActionCmd(
                                                  _actionResName[3]);
                                            },
                                            child: Image.asset(
                                              'assets/images/mini_shake_hand.webp',
                                              //width: 64.w,
                                              height: 113.h,
                                              fit: BoxFit.fill, // 设置图片填充方式
                                            )),
                                        Text(
                                          '握手',
                                          style: TextStyle(
                                            color: (controller.isMoving.value || controller.isVideoLoading.value)? Color(_textcolor).withOpacity(0.3):Color(_textcolor),
                                            fontSize: 22.sp,
                                          ),
                                        )
                                      ])),
                                ],
                              ),
                            ),

                            ///第2行动作
                            controller.isActionViewExpanded.value
                                ? Container(
                              width: ScreenUtil().screenWidth,
                              padding: EdgeInsets.only(top: 20.h),
                              height: 174.h,
                              child: Row(
                                //mainAxisAlignment: MainAxisAlignment.spaceBetween, // 子控件之间均匀分布，不包括边缘
                                children: [
                                  Container(
                                    width: ScreenUtil().screenWidth / 4,
                                    alignment: Alignment.center,
                                    child: Column(children: [
                                      controller.isMoving.value || controller.isVideoLoading.value ?
                                      Image.asset(
                                        'assets/images/mini_bow.webp',
                                        //width: 95.w,
                                        color: Colors.white.withOpacity(0.3), // 设置透明度为30%
                                        colorBlendMode: BlendMode.modulate,
                                        height: 113.h,
                                        fit: BoxFit.fill, // 设置图片填充方式
                                      ) :
                                      GestureDetector(
                                          onTap: () {
                                            controller.sendActionCmd(
                                                _actionResName[4]);
                                          },
                                          child: Image.asset(
                                            'assets/images/mini_bow.webp',
                                            //width: 95.w,
                                            height: 113.h,
                                            fit:
                                            BoxFit.fill, // 设置图片填充方式
                                          )),
                                      Text(
                                        '鞠躬',
                                        style: TextStyle(
                                          color: (controller.isMoving.value || controller.isVideoLoading.value)? Color(_textcolor).withOpacity(0.3):Color(_textcolor),
                                          fontSize: 22.sp,
                                        ),
                                      )
                                    ]),
                                  ),
                                  Container(
                                    width: ScreenUtil().screenWidth / 4,
                                    alignment: Alignment.center,
                                    child: Column(children: [
                                      controller.isMoving.value || controller.isVideoLoading.value ?
                                      Image.asset(
                                        'assets/images/mini_sell_moe.webp',
                                        //width: 95.w,
                                        color: Colors.white.withOpacity(0.3), // 设置透明度为30%
                                        colorBlendMode: BlendMode.modulate,
                                        height: 113.h,
                                        fit: BoxFit.fill, // 设置图片填充方式
                                      ) :
                                      GestureDetector(
                                          onTap: () {
                                            controller.sendActionCmd(
                                                _actionResName[5]);
                                          },
                                          child: Image.asset(
                                            'assets/images/mini_sell_moe.webp',
                                            //width: 86.w,
                                            height: 113.h,
                                            fit:
                                            BoxFit.fill, // 设置图片填充方式
                                          )),
                                      Text(
                                        '飞吻',
                                        style: TextStyle(
                                          color: (controller.isMoving.value || controller.isVideoLoading.value)? Color(_textcolor).withOpacity(0.3):Color(_textcolor),
                                          fontSize: 22.sp,
                                        ),
                                      )
                                    ]),
                                  ),
                                ],
                              ),
                            )
                                : Container(
                              width: 0,
                              height: 0,
                            ),

                            //展开按钮
                            GestureDetector(
                              onTap: () {
                                controller.isActionViewExpanded.value =
                                !controller.isActionViewExpanded.value;
                              },
                              child: Container(
                                width: 100.w,
                                height: 35.h,
                                //color: Colors.red,
                                child: Icon(
                                  controller.isActionViewExpanded.value
                                      ? Icons.keyboard_arrow_up
                                      : Icons.keyboard_arrow_down, // 向下的箭头图标
                                  size: 35.h, // 图标的大小
                                  color: Color(0xFF818793), // 图标的颜色
                                ),
                              ),
                            )
                          ],
                        ),
                      ))),

                  /// tts输入框
                  Positioned(
                    bottom: 90.h + MediaQuery.of(context).padding.bottom,
                    left: 0,
                    width: ScreenUtil().screenWidth,
                    //height: 80.h,
                    child: Obx(() => controller.isMoveControlViewShowed.value
                        ? Container(
                      height: 0,
                      width: 0,
                    )
                        : Container(
                      width: ScreenUtil().screenWidth,
                      color: Colors.white,
                      padding: EdgeInsets.only(top: 10.h, bottom: 10.h),
                      child: Column(
                        children: [
                          controller.ttsTextTips.value.isNotEmpty
                              ? Container(
                            padding: EdgeInsets.only(
                                left: 150.w,
                                top: 21.h,
                                bottom: 19.h),
                            alignment: Alignment.topLeft,
                            child: Text(
                                controller.ttsTextTips.value, // 对应 android:text
                                style: TextStyle(
                                  color: Color(
                                      0xffe53737), // 对应 android:textColor="#ff3f5579"
                                  fontSize: 28
                                      .sp, // 对应 android:textSize="28sp"
                                )),
                          )
                              : Container(
                            width: 0,
                            height: 0,
                          ),
                          Row(
                            children: [
                              Padding(
                                padding: EdgeInsets.only(
                                  left: 24.w,
                                ),
                                child: Text(
                                  '${controller.lengthWordEnterd}/120',
                                  style: TextStyle(
                                    color: controller.lengthWordEnterd
                                        .value >
                                        120
                                        ? Color(0xFFE53737)
                                        : Color(0xFF666666), // 设置文本颜色
                                    fontSize: 26.sp, // 设置字体大小
                                  ),
                                ),
                              ),
                              Expanded(
                                child: Container(
                                  margin: EdgeInsets.only(
                                      left: 20.w, right: 30.w),
                                  //width: 520.w, // 设置宽度
                                  //height: 60.h, // 设置高度
                                  //padding: EdgeInsets.symmetric(horizontal: 16.0), // 内边距以保证文本不紧贴边框
                                  decoration: BoxDecoration(
                                    border: Border.all(
                                      color: Color(0xffbfbebe), // 边框颜色
                                      //color: Color(0xffff0000), // 边框颜色
                                      width: 1.0, // 边框宽度
                                    ),
                                    borderRadius: BorderRadius.circular(
                                        30.w), // 圆角半径
                                  ),
                                  child: TextField(
                                    maxLines: null, // 自动换行并支持任意行数
                                    controller:
                                    controller.ttsInputController,
                                    focusNode: _focusNode,
                                    onTapOutside: (PointerDownEvent event){
                                      _focusNode.unfocus();
                                    },
                                    decoration: InputDecoration(
                                      border:
                                      InputBorder.none, // 移除默认边框
                                      // 如果你还想去除聚焦时的边框，可以添加以下属性：
                                      focusedBorder: InputBorder.none,
                                      // 如果你想去除错误状态下的边框，可以添加以下属性：
                                      errorBorder: InputBorder.none,
                                      // 如果你想去除获得焦点且有错误时的边框，可以添加以下属性：
                                      focusedErrorBorder:
                                      InputBorder.none,
                                    ),
                                    onChanged: (text) {
                                      controller
                                          .onTTSInputChanged(text);
                                    },
                                  ),
                                ),
                              ),
                              Padding(
                                padding: EdgeInsets.only(right: 20.w),
                                child: GestureDetector(
                                  onTap: () {
                                    controller.saveTTS();
                                  },
                                  child: Image.asset(
                                    controller.isTtsInputConfirmEnabled
                                        .value
                                        ? 'assets/images/ic_confirm.png'
                                        : 'assets/images/ic_confirm_disable.png',
                                    width: 54.w,
                                    fit: BoxFit.fill, // 设置图片填充方式
                                  ),
                                ),
                              )
                            ],
                          )
                        ],
                      ),
                    )),
                  ),
                  //),
                  //),

                  /// 底部按钮
                  Positioned(
                      height: 90.h,
                      width: ScreenUtil().screenWidth,
                      bottom: 0 + MediaQuery.of(context).padding.bottom,
                      child: Obx(() => Container(
                        color: Colors.white,
                        child: Stack(
                          children: [
                            Positioned(
                                bottom: 20.h,
                                left: 150.w,
                                child: controller.isVideoLoading.value ?
                                Image.asset(
                                  controller.isLocalAudioStated.value
                                      ? 'assets/images/ic_microphone_on.png'
                                      : 'assets/images/ic_microphone_off.png',
                                  color: Colors.white.withOpacity(0.3), // 设置透明度为30%
                                  colorBlendMode: BlendMode.modulate,
                                  width: 50.w,
                                  fit: BoxFit.fill, // 设置图片填充方式
                                ):
                                GestureDetector(
                                  onTap: () {
                                    controller.changeMicState();
                                  },
                                  child: Image.asset(
                                    controller.isLocalAudioStated.value
                                        ? 'assets/images/ic_microphone_on.png'
                                        : 'assets/images/ic_microphone_off.png',
                                    width: 50.w,
                                    fit: BoxFit.fill, // 设置图片填充方式
                                  ),
                                )),
                            Positioned(
                                left: 216.w,
                                bottom: 27.h,
                                child: Text(
                                  controller.isLocalAudioStated.value
                                      ? "关闭"
                                      : '开启',
                                  style: TextStyle(
                                    color: controller.isVideoLoading.value? Color(_textcolor).withOpacity(0.3):Color(_textcolor),
                                    fontSize: 26.sp,
                                  ),
                                )),
                            Positioned(
                                bottom: 20.h,
                                right: 207.w,
                                child: (controller.isMoving.value || controller.isVideoLoading.value) ?
                                Image.asset(
                                  'assets/images/ic_reset_body.png',
                                  color: Colors.white.withOpacity(0.3), // 设置透明度为30%
                                  colorBlendMode: BlendMode.modulate,
                                  width: 50.w,
                                  fit: BoxFit.fill, // 设置图片填充方式
                                ):
                                GestureDetector(
                                  onTap: () {
                                    controller.sendStandUpCmd();
                                  },
                                  child: Image.asset(
                                    'assets/images/ic_reset_body.png',
                                    width: 50.w,
                                    fit: BoxFit.fill, // 设置图片填充方式
                                  ),
                                )),
                            Positioned(
                                right: 139.w,
                                bottom: 27.h,
                                child: Text(
                                  '复位',
                                  style: TextStyle(
                                    color: (controller.isMoving.value|| controller.isVideoLoading.value)? Color(_textcolor).withOpacity(0.3):Color(_textcolor),
                                    fontSize: 26.sp,
                                  ),
                                ))
                          ],
                        ),
                      )))
                ],
              ))

          //)
              : Stack(
            children: [
              Positioned(
                top: 0,
                child: SizedBox(
                    width: ScreenUtil().screenWidth,
                    height: ScreenUtil().screenHeight,
                    child: trtcCloudVideoView
                ),
              ),

              // 返回按钮
              Positioned(
                  top: 24.h,
                  left: 50.w,
                  child: GestureDetector(
                    onTap: () {
                      controller.changeScrennDirection(true);
                    },
                    child: Image.asset(
                      'assets/images/ic_back.png',
                      width: 72.w,
                      //height: 72.h,
                      fit: BoxFit.fill, // 设置图片填充方式
                    ),
                  )),

              // 按鈕
              Align(
                  alignment: Alignment.bottomCenter,
                  child: Obx(() =>  Container(
                    margin: EdgeInsets.only(bottom: 100.h),
                    width: 276.w,
                    child: Row(
                      children: [
                        controller.isVideoLoading.value ?
                        Image.asset(
                          controller.isLocalAudioStated.value
                              ? 'assets/images/ic_microphone_on.png'
                              : 'assets/images/ic_microphone_off2.png',
                          color: Colors.white.withOpacity(0.3), // 设置透明度为30%
                          colorBlendMode: BlendMode.modulate,
                          width: 72.w,
                          fit: BoxFit.fill, // 设置图片填充方式
                        ):
                        GestureDetector(
                          onTap: () {
                            controller.changeMicState();
                          },
                          child: Image.asset(
                            controller.isLocalAudioStated.value
                                ? 'assets/images/ic_microphone_on.png'
                                : 'assets/images/ic_microphone_off2.png',
                            width: 72.w,
                            fit: BoxFit.fill, // 设置图片填充方式
                          ),
                        ),
                        Padding(padding: EdgeInsets.only(left: 30.w)),
                        GestureDetector(
                            onTap: () {},
                            child: GestureDetector(
                              onTap: () {
                                controller.sendStandUpCmd();
                              },
                              child: Image.asset(
                                controller.isMoving.value ? 'assets/images/ic_reset_body3.png':'assets/images/ic_reset_body2.png',
                                width: 72.w,
                                fit: BoxFit.fill, // 设置图片填充方式
                              ),
                            )),
                        Padding(padding: EdgeInsets.only(left: 30.w)),
                        GestureDetector(
                          onTap: () {
                            controller.changeScrennDirection(true);
                          },
                          child: Image.asset(
                            'assets/images/ic_screen_mode_switch.png',
                            width: 72.w,
                            fit: BoxFit.fill, // 设置图片填充方式
                          ),
                        )
                      ],
                    ),
                  ))),

              ///移动操控杆
              Positioned(
                  left: 173.w,
                  top: 348.h,
                  width: 348.w,
                  height: 348.w,
                  child: Obx(() =>  MoveWidget(
                    background: 'assets/images/bg_move_wideland.png',
                    backgroundUnenabled: 'assets/images/bg_move_wideland_unable.png',
                    icon: 'assets/images/ic_move.png',
                    iconUnenabled: 'assets/images/ic_move_wideland_unable.png',
                    radiusBackground: 174.w,
                    radiusIcon: 61.5.w,
                    onChange: (double angle) {
                      controller.onMoveAngleChange(angle);
                    },
                    onStartMove: () {
                      controller.isMoving.value = true;
                    },
                    onStopMove: () {
                      controller.isMoving.value = false;
                      controller.onMoveStop();
                    },
                    isMoveStick: true,
                    enable: !controller.isVideoLoading.value,
                  ))),
              // 头部转动操作杆
              Positioned(
                  right: 174.w,
                  top: 348.h,
                  width: 348.w,
                  height: 348.w,
                  child: Obx(() =>  MoveWidget(
                    background: 'assets/images/bg_rotate_wideland.png',
                    backgroundUnenabled: 'assets/images/bg_rotate_wideland_unable.png',
                    icon: 'assets/images/ic_rotate.png',
                    iconUnenabled: 'assets/images/ic_rotate_wideland_unable.png',
                    radiusBackground: 174.w,
                    radiusIcon: 61.5.w,
                    onChange: (double angle) {
                      controller.onHeadMoveChange(angle);
                    },
                    onStartMove: () {
                      controller.isMoving.value = true;
                    },
                    onStopMove: () {
                      controller.isMoving.value = false;
                      controller.onHeadMoveStop();
                    },
                    enable: !controller.isVideoLoading.value,
                  ))),

              ///动作列表
              Positioned(
                bottom: 0,
                right: 0,
                height: ScreenUtil().screenHeight,
                width: 170.w,
                child: Container(
                    color: Color(0x000000).withOpacity(0.5),
                    child:  ListView.builder(
                      //itemViewHeight: 206.h,
                      itemCount: _actionResName.length,
                      scrollDirection: Axis.vertical,
                      itemBuilder: (context, index) {
                        int actualIndex = index;
                        return Container(
                          //padding: const EdgeInsets.all(8.0),
                            height: 206.h,
                            //width: 200.w,
                            // color: Colors.red.shade100,
                            child: Stack(
                              children: <Widget>[
                                Obx(() => Positioned(
                                  top: 24.h,
                                  left: 0,
                                  right: 0,
                                  child: (
                                      (controller.currentPlayingAction.value != "" && controller.currentPlayingAction.value != _actionResName[actualIndex])
                                  || controller.isMoving.value
                                  || controller.isVideoLoading.value)
                                      ? Image.asset(
                                    _actionImg[actualIndex],
                                    color: Colors.white.withOpacity(0.3), // 设置透明度为30%
                                    colorBlendMode: BlendMode.modulate, // 使用适当的混合模式
                                    //width: 95.w,
                                    height: 136.h,
                                    fit: BoxFit
                                        .fitHeight, // 设置图片填充方式
                                  )
                                      : GestureDetector(
                                      onTap: () {
                                        controller.sendActionCmd(
                                            _actionResName[actualIndex]);
                                      },
                                      child: Image.asset(
                                        _actionImg[actualIndex],
                                        //width: 95.w,
                                        height: 136.h,
                                        fit: BoxFit
                                            .fitHeight, // 设置图片填充方式
                                      )),
                                )),
                                Positioned(
                                    top: 65.h,
                                    left: 0,
                                    right: 0,
                                    child: Obx(
                                          () => controller.currentPlayingAction
                                          .value ==
                                          _actionResName[actualIndex]
                                          ? RotatingCircle(
                                        radius: 40.h,
                                      )
                                          : Container(
                                        width: 0,
                                        height: 0,
                                      ),
                                    )),
                                Obx(
                                      () => Positioned(
                                    top: 176.h,
                                    left: 0,
                                    right: 0,
                                    child: Text(
                                      _actionName[actualIndex],
                                      textAlign: TextAlign.center, // 文字居中对齐
                                      style: TextStyle(
                                          fontSize: 22.sp,
                                          color: (
                                              (controller.currentPlayingAction.value != "" && controller.currentPlayingAction.value != _actionResName[actualIndex])
                                          || controller.isMoving.value
                                                  || controller.isVideoLoading.value)
                                              ? Colors.white
                                              .withOpacity(0.3)
                                              : Colors.white), // 设置字体大小
                                    ),
                                  ),
                                )
                              ],
                            ));
                      },
                    ))
                ,
              )
            ],
          );
        }
        )



    )
    ;
  }
}
